package 背包问题;

import org.junit.Test;

/**
 * @Classname AllPackage
 * @Description TODO
 * @Date 2022/3/25 17:18
 * @Created by xjl
 */
public class AllPackageV2 {
    /**
     * @description ks(i, t) = max{ks(i-1, t - V[i] * k) + P[i] * k}; （0 <= k * V[i] <= t）
     * @param: v
     * @param: w
     * @param: k
     * @param: c
     * @date: 2022/3/25 17:20
     * @return: int
     * @author: xjl
     */
    private int AllPackage(int[] v, int[] w, int n, int c) {
        int[] result = new int[c + 1];
        for (int m = 0; m < n; m++) {
            for (int j = w[m]; j <= c; j++) {
                result[j] = Math.max(result[j], result[j - w[m]] + v[m]);
            }
        }
        return result[c];
    }

    @Test
    public void TestAllPackage() {
        int[] w = {0, 5, 8};
        int[] V = {0, 5, 7};
        int k = 2;
        int c = 10;
        int i = AllPackage(w, w, k, c);
        System.out.println(i);

    }
}
